package com.aa;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog;

public class PhoneUtilsFunction {

	public static boolean deleteCallLogByNumber(Context pContext,String pNumber){
		ContentResolver _ContentResolver = pContext.getContentResolver();
		boolean _Result = false;
		if (pNumber != null && pNumber.length() > 0) {
			try {
				_Result = _ContentResolver.delete(CallLog.Calls.CONTENT_URI, "number=?", new String[]{pNumber}) > 0;
				return _Result;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return false;
	}
	
   public static boolean clearCallLog(Context pContext){
	   pContext.getContentResolver().delete(CallLog.Calls.CONTENT_URI, null, null);
	   return true;
  }
   
   public static void insertRecentContact(Context pContext, String pNumber)
   {
     try
     {
       ContentValues _ContentValues = new ContentValues();
       _ContentValues.put("number", pNumber);
       _ContentValues.put("date", Long.valueOf(System.currentTimeMillis()));
       _ContentValues.put("duration", Integer.valueOf(0));
       _ContentValues.put("type", Integer.valueOf(2));
       _ContentValues.put("new", Integer.valueOf(1));
       _ContentValues.put("name", "");
       _ContentValues.put("numberlabel", "");
       _ContentValues.put("numbertype", Integer.valueOf(0));
     
       pContext.getContentResolver().insert(CallLog.Calls.CONTENT_URI, _ContentValues);
       return;
     }
     catch (Exception e)
     {
       e.printStackTrace();
     }
   }

   public void deleteCallLogByNumber(Context pContext, String[] pCondition)
   {
     ContentResolver _ContentResolver = pContext.getContentResolver();
     Cursor _Cursor = _ContentResolver.query(CallLog.Calls.CONTENT_URI, new String[] { "_id" }, "number=?", pCondition, "_id desc limit 1");
     if (_Cursor.moveToFirst())
     {
       int i = _Cursor.getInt(0);
       Uri _Uri = CallLog.Calls.CONTENT_URI;
       String[] arrayOfString = new String[1];
    //   arrayOfString[0] = i;
       _ContentResolver.delete(_Uri, "_id=?", arrayOfString);
     }
   }
}
